package cn.ibizlab.odoo.core.odoo_gamification.service.impl;

import java.io.Serializable;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.HashMap;
import java.math.BigInteger;
import java.util.Collection;

import lombok.extern.slf4j.Slf4j;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cglib.beans.BeanCopier;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.Pageable;
import cn.ibizlab.odoo.core.client.model.Igamification_badge;
import cn.ibizlab.odoo.core.odoo_gamification.domain.Gamification_badge;
import cn.ibizlab.odoo.core.odoo_gamification.filter.Gamification_badgeSearchContext;
import cn.ibizlab.odoo.core.odoo_gamification.service.IGamification_badgeService;
import cn.ibizlab.odoo.util.SearchResult;
import cn.ibizlab.odoo.util.log.IBIZLog;

/**
 * 实体[游戏化徽章] 服务对象接口实现
 */
@Slf4j
@IBIZLog
@Service
public class Gamification_badgeServiceImpl implements IGamification_badgeService {

    @Autowired
    private cn.ibizlab.odoo.core.client.service.Igamification_badgeClientService gamification_badgeClientService;

    @Override
    public boolean remove(Integer id) {
        boolean bOk = false ;
        Igamification_badge clientModel = gamification_badgeClientService.createModel();
        clientModel.setId(id);
        gamification_badgeClientService.remove(clientModel) ;
        bOk = true ;
        return bOk ;
    }

    @Override
    public void createBatch(List<Gamification_badge> gamification_badges, int batchSize) {

                        //gamification_badgeClientService.createBatch(gamification_badges,batchSize) ;

    }

    @Override
    public boolean update(Gamification_badge gamification_badge) {
        boolean bOk = false ;
        Igamification_badge clientModel = this.convert2Model(gamification_badge,null);
        gamification_badgeClientService.update(clientModel) ;
        this.convert2Domain(clientModel,gamification_badge) ;
        bOk = true;
        return bOk ;
    }

    @Override
    public void updateBatch(List<Gamification_badge> gamification_badges, int batchSize) {

        //gamification_badgeClientService.updateBatch(gamification_badges,batchSize) ;

    }

    @Override
    public void removeBatch(Collection<? extends Serializable> idList, int batchSize) {

        //gamification_badgeClientService.removeBatch(gamification_badges) ;

    }

    @Override
    public boolean create(Gamification_badge gamification_badge) {
        boolean bOk = false ;
        Igamification_badge clientModel = this.convert2Model(gamification_badge,null);
        gamification_badgeClientService.create(clientModel) ;
        this.convert2Domain(clientModel,gamification_badge);
        bOk = true ;

        return bOk ;
    }

    @Override
    public Gamification_badge get(Integer id) {
        Igamification_badge clientModel = gamification_badgeClientService.createModel();
        clientModel.setId(id);
        gamification_badgeClientService.get(clientModel) ;
        return this.convert2Domain(clientModel,null);
    }

    @Override
    public Gamification_badge get(Gamification_badge gamification_badge) {
        Gamification_badge retgamification_badge = this.get(gamification_badge.getId()) ;
    	BeanCopier copier=BeanCopier.create(retgamification_badge.getClass(), gamification_badge.getClass(), false);
        copier.copy(retgamification_badge, gamification_badge, null);
        return gamification_badge ;
    }

    /**
     * 查询集合 默认查询
     */
    @Override
    public Page<Gamification_badge> searchDefault(Gamification_badgeSearchContext context) {
        List<Gamification_badge> list = new ArrayList<Gamification_badge>();
        Page<cn.ibizlab.odoo.core.client.model.Igamification_badge> clientModelList = gamification_badgeClientService.search(context) ;
        for(cn.ibizlab.odoo.core.client.model.Igamification_badge clientModel : clientModelList){
            list.add( this.convert2Domain(clientModel,null));
        }
        return new PageImpl<Gamification_badge>(list, context.getPageable(), clientModelList.getTotalElements());
    }


    /**
     * 根据用户查询
     */
    @Override
    public Page<Gamification_badge> selectByOdoo_create(Integer id){
        Gamification_badgeSearchContext context = new Gamification_badgeSearchContext();
        if(!org.springframework.util.StringUtils.isEmpty(id)){
            cn.ibizlab.odoo.util.SearchFieldFilter fieldFilter=new cn.ibizlab.odoo.util.SearchFieldFilter();
            fieldFilter.setParam("id");
            fieldFilter.setCondition(cn.ibizlab.odoo.util.enums.SearchFieldType.EQ);
            fieldFilter.setValue(id);
            context.getCondition().add(fieldFilter);
        }
        List<Gamification_badge> list = new ArrayList<Gamification_badge>();
        Page<cn.ibizlab.odoo.core.client.model.Igamification_badge> clientModelList = gamification_badgeClientService.search(context) ;
        for(cn.ibizlab.odoo.core.client.model.Igamification_badge clientModel : clientModelList){
            list.add( this.convert2Domain(clientModel,null));
        }
        return new PageImpl<Gamification_badge>(list, context.getPageable(), clientModelList.getTotalElements());

    }

    /**
     * 根据用户查询
     */
    @Override
    public Page<Gamification_badge> selectByOdoo_write(Integer id){
        Gamification_badgeSearchContext context = new Gamification_badgeSearchContext();
        if(!org.springframework.util.StringUtils.isEmpty(id)){
            cn.ibizlab.odoo.util.SearchFieldFilter fieldFilter=new cn.ibizlab.odoo.util.SearchFieldFilter();
            fieldFilter.setParam("id");
            fieldFilter.setCondition(cn.ibizlab.odoo.util.enums.SearchFieldType.EQ);
            fieldFilter.setValue(id);
            context.getCondition().add(fieldFilter);
        }
        List<Gamification_badge> list = new ArrayList<Gamification_badge>();
        Page<cn.ibizlab.odoo.core.client.model.Igamification_badge> clientModelList = gamification_badgeClientService.search(context) ;
        for(cn.ibizlab.odoo.core.client.model.Igamification_badge clientModel : clientModelList){
            list.add( this.convert2Domain(clientModel,null));
        }
        return new PageImpl<Gamification_badge>(list, context.getPageable(), clientModelList.getTotalElements());

    }



    public Igamification_badge convert2Model(Gamification_badge domain , Igamification_badge model) {
        if(domain == null)
            return model ;
        if(model==null){
            model = gamification_badgeClientService.createModel() ;
        }

         if(domain.getRule_authDirtyFlag())
            model.setRule_auth(domain.getRule_auth());
         if(domain.getRule_max_numberDirtyFlag())
            model.setRule_max_number(domain.getRule_max_number());
         if(domain.getDescriptionDirtyFlag())
            model.setDescription(domain.getDescription());
         if(domain.getRule_maxDirtyFlag())
            model.setRule_max(domain.getRule_max());
         if(domain.getRule_auth_user_idsDirtyFlag())
            model.setRule_auth_user_ids(domain.getRule_auth_user_ids());
         if(domain.getRule_auth_badge_idsDirtyFlag())
            model.setRule_auth_badge_ids(domain.getRule_auth_badge_ids());
         if(domain.getMessage_needaction_counterDirtyFlag())
            model.setMessage_needaction_counter(domain.getMessage_needaction_counter());
         if(domain.getMessage_attachment_countDirtyFlag())
            model.setMessage_attachment_count(domain.getMessage_attachment_count());
         if(domain.getRemaining_sendingDirtyFlag())
            model.setRemaining_sending(domain.getRemaining_sending());
         if(domain.getMessage_follower_idsDirtyFlag())
            model.setMessage_follower_ids(domain.getMessage_follower_ids());
         if(domain.getMessage_idsDirtyFlag())
            model.setMessage_ids(domain.getMessage_ids());
         if(domain.getMessage_main_attachment_idDirtyFlag())
            model.setMessage_main_attachment_id(domain.getMessage_main_attachment_id());
         if(domain.getStat_myDirtyFlag())
            model.setStat_my(domain.getStat_my());
         if(domain.getImageDirtyFlag())
            model.setImage(domain.getImage());
         if(domain.getDisplay_nameDirtyFlag())
            model.setDisplay_name(domain.getDisplay_name());
         if(domain.getMessage_partner_idsDirtyFlag())
            model.setMessage_partner_ids(domain.getMessage_partner_ids());
         if(domain.getMessage_is_followerDirtyFlag())
            model.setMessage_is_follower(domain.getMessage_is_follower());
         if(domain.getMessage_channel_idsDirtyFlag())
            model.setMessage_channel_ids(domain.getMessage_channel_ids());
         if(domain.getUnique_owner_idsDirtyFlag())
            model.setUnique_owner_ids(domain.getUnique_owner_ids());
         if(domain.getWebsite_message_idsDirtyFlag())
            model.setWebsite_message_ids(domain.getWebsite_message_ids());
         if(domain.get__last_updateDirtyFlag())
            model.set__last_update(domain.get__last_update());
         if(domain.getMessage_unreadDirtyFlag())
            model.setMessage_unread(domain.getMessage_unread());
         if(domain.getMessage_has_error_counterDirtyFlag())
            model.setMessage_has_error_counter(domain.getMessage_has_error_counter());
         if(domain.getLevelDirtyFlag())
            model.setLevel(domain.getLevel());
         if(domain.getActiveDirtyFlag())
            model.setActive(domain.getActive());
         if(domain.getOwner_idsDirtyFlag())
            model.setOwner_ids(domain.getOwner_ids());
         if(domain.getMessage_has_errorDirtyFlag())
            model.setMessage_has_error(domain.getMessage_has_error());
         if(domain.getMessage_unread_counterDirtyFlag())
            model.setMessage_unread_counter(domain.getMessage_unread_counter());
         if(domain.getGoal_definition_idsDirtyFlag())
            model.setGoal_definition_ids(domain.getGoal_definition_ids());
         if(domain.getStat_my_monthly_sendingDirtyFlag())
            model.setStat_my_monthly_sending(domain.getStat_my_monthly_sending());
         if(domain.getIdDirtyFlag())
            model.setId(domain.getId());
         if(domain.getStat_countDirtyFlag())
            model.setStat_count(domain.getStat_count());
         if(domain.getNameDirtyFlag())
            model.setName(domain.getName());
         if(domain.getStat_this_monthDirtyFlag())
            model.setStat_this_month(domain.getStat_this_month());
         if(domain.getMessage_needactionDirtyFlag())
            model.setMessage_needaction(domain.getMessage_needaction());
         if(domain.getWrite_dateDirtyFlag())
            model.setWrite_date(domain.getWrite_date());
         if(domain.getCreate_dateDirtyFlag())
            model.setCreate_date(domain.getCreate_date());
         if(domain.getStat_count_distinctDirtyFlag())
            model.setStat_count_distinct(domain.getStat_count_distinct());
         if(domain.getStat_my_this_monthDirtyFlag())
            model.setStat_my_this_month(domain.getStat_my_this_month());
         if(domain.getChallenge_idsDirtyFlag())
            model.setChallenge_ids(domain.getChallenge_ids());
         if(domain.getGranted_employees_countDirtyFlag())
            model.setGranted_employees_count(domain.getGranted_employees_count());
         if(domain.getWrite_uid_textDirtyFlag())
            model.setWrite_uid_text(domain.getWrite_uid_text());
         if(domain.getCreate_uid_textDirtyFlag())
            model.setCreate_uid_text(domain.getCreate_uid_text());
         if(domain.getCreate_uidDirtyFlag())
            model.setCreate_uid(domain.getCreate_uid());
         if(domain.getWrite_uidDirtyFlag())
            model.setWrite_uid(domain.getWrite_uid());
        return model ;
    }

    public Gamification_badge convert2Domain( Igamification_badge model ,Gamification_badge domain) {
        if(model == null)
            return domain ;
        if(domain == null){
            domain = new Gamification_badge();
        }

        if(model.getRule_authDirtyFlag())
            domain.setRule_auth(model.getRule_auth());
        if(model.getRule_max_numberDirtyFlag())
            domain.setRule_max_number(model.getRule_max_number());
        if(model.getDescriptionDirtyFlag())
            domain.setDescription(model.getDescription());
        if(model.getRule_maxDirtyFlag())
            domain.setRule_max(model.getRule_max());
        if(model.getRule_auth_user_idsDirtyFlag())
            domain.setRule_auth_user_ids(model.getRule_auth_user_ids());
        if(model.getRule_auth_badge_idsDirtyFlag())
            domain.setRule_auth_badge_ids(model.getRule_auth_badge_ids());
        if(model.getMessage_needaction_counterDirtyFlag())
            domain.setMessage_needaction_counter(model.getMessage_needaction_counter());
        if(model.getMessage_attachment_countDirtyFlag())
            domain.setMessage_attachment_count(model.getMessage_attachment_count());
        if(model.getRemaining_sendingDirtyFlag())
            domain.setRemaining_sending(model.getRemaining_sending());
        if(model.getMessage_follower_idsDirtyFlag())
            domain.setMessage_follower_ids(model.getMessage_follower_ids());
        if(model.getMessage_idsDirtyFlag())
            domain.setMessage_ids(model.getMessage_ids());
        if(model.getMessage_main_attachment_idDirtyFlag())
            domain.setMessage_main_attachment_id(model.getMessage_main_attachment_id());
        if(model.getStat_myDirtyFlag())
            domain.setStat_my(model.getStat_my());
        if(model.getImageDirtyFlag())
            domain.setImage(model.getImage());
        if(model.getDisplay_nameDirtyFlag())
            domain.setDisplay_name(model.getDisplay_name());
        if(model.getMessage_partner_idsDirtyFlag())
            domain.setMessage_partner_ids(model.getMessage_partner_ids());
        if(model.getMessage_is_followerDirtyFlag())
            domain.setMessage_is_follower(model.getMessage_is_follower());
        if(model.getMessage_channel_idsDirtyFlag())
            domain.setMessage_channel_ids(model.getMessage_channel_ids());
        if(model.getUnique_owner_idsDirtyFlag())
            domain.setUnique_owner_ids(model.getUnique_owner_ids());
        if(model.getWebsite_message_idsDirtyFlag())
            domain.setWebsite_message_ids(model.getWebsite_message_ids());
        if(model.get__last_updateDirtyFlag())
            domain.set__last_update(model.get__last_update());
        if(model.getMessage_unreadDirtyFlag())
            domain.setMessage_unread(model.getMessage_unread());
        if(model.getMessage_has_error_counterDirtyFlag())
            domain.setMessage_has_error_counter(model.getMessage_has_error_counter());
        if(model.getLevelDirtyFlag())
            domain.setLevel(model.getLevel());
        if(model.getActiveDirtyFlag())
            domain.setActive(model.getActive());
        if(model.getOwner_idsDirtyFlag())
            domain.setOwner_ids(model.getOwner_ids());
        if(model.getMessage_has_errorDirtyFlag())
            domain.setMessage_has_error(model.getMessage_has_error());
        if(model.getMessage_unread_counterDirtyFlag())
            domain.setMessage_unread_counter(model.getMessage_unread_counter());
        if(model.getGoal_definition_idsDirtyFlag())
            domain.setGoal_definition_ids(model.getGoal_definition_ids());
        if(model.getStat_my_monthly_sendingDirtyFlag())
            domain.setStat_my_monthly_sending(model.getStat_my_monthly_sending());
        if(model.getIdDirtyFlag())
            domain.setId(model.getId());
        if(model.getStat_countDirtyFlag())
            domain.setStat_count(model.getStat_count());
        if(model.getNameDirtyFlag())
            domain.setName(model.getName());
        if(model.getStat_this_monthDirtyFlag())
            domain.setStat_this_month(model.getStat_this_month());
        if(model.getMessage_needactionDirtyFlag())
            domain.setMessage_needaction(model.getMessage_needaction());
        if(model.getWrite_dateDirtyFlag())
            domain.setWrite_date(model.getWrite_date());
        if(model.getCreate_dateDirtyFlag())
            domain.setCreate_date(model.getCreate_date());
        if(model.getStat_count_distinctDirtyFlag())
            domain.setStat_count_distinct(model.getStat_count_distinct());
        if(model.getStat_my_this_monthDirtyFlag())
            domain.setStat_my_this_month(model.getStat_my_this_month());
        if(model.getChallenge_idsDirtyFlag())
            domain.setChallenge_ids(model.getChallenge_ids());
        if(model.getGranted_employees_countDirtyFlag())
            domain.setGranted_employees_count(model.getGranted_employees_count());
        if(model.getWrite_uid_textDirtyFlag())
            domain.setWrite_uid_text(model.getWrite_uid_text());
        if(model.getCreate_uid_textDirtyFlag())
            domain.setCreate_uid_text(model.getCreate_uid_text());
        if(model.getCreate_uidDirtyFlag())
            domain.setCreate_uid(model.getCreate_uid());
        if(model.getWrite_uidDirtyFlag())
            domain.setWrite_uid(model.getWrite_uid());
        return domain ;
    }


}
